package Get4;

use Moose;
use HTML::TreeBuilder;


has file => (is => 'rw', default => 'file.html');
has tree => (is => 'rw', lazy_build => 1);

has name => (
	     is => 'ro', 
	     lazy_build => 1,
	    );

has w => (
	     is => 'ro', 
	     lazy_build => 1,
	    );

has look_down_index => (is => 'rw', lazy_build => 1);

sub _build_look_down_index {
    
    {
	name => [ id => 'name' ],
	w =>    [ id => qr/w.lc.me/ ]
    }
}



sub _build_name {
    my($self)=@_;

    $self->look_down;
}

sub _build_w {
    my($self)=@_;

    $self->look_down;
}

sub _build_tree {
    my($self)=@_;

    HTML::TreeBuilder->new_from_file($self->file);
}

sub look_down {
    my($self)=@_;

    my ($package, $filename, $line, $subroutine) = caller(1);

    if ($subroutine =~ /::(\w+)/) {
	if ($1 =~ /_build_(\w+)/) {
	    my $look_down = $self->look_down_index->{$1} ;
	    $self->tree->look_down( @$look_down ) ;
	}
    } else {
	die $subroutine;
    }
    
}


1;

package main;

my $o = Get4->new;

warn $o->w->as_HTML;

1;
